#include "FontUnit.h"


FontUnit::FontUnit(const QString &family, int pointSize, bool bold, bool italic, bool underline,QObject *parent)
    : QObject(parent),fontFamily(family), fontPointSize(pointSize), fontBold(bold), fontItalic(italic), fontUnderline(underline)
{
}


FontUnit &FontUnit::instance(QObject *parent)
{
    static FontUnit instance("Cascadia", 12, true, false, false, parent);;  // 静态实例，应用中唯一的FontUnit对象
    return instance;
}

void FontUnit::setFamily(const QString &family)
{
    fontFamily = family;
}

QString FontUnit::family() const
{
    return fontFamily;
}

void FontUnit::setPointSize(int size)
{
    fontPointSize = size;
}

int FontUnit::pointSize() const
{
    return fontPointSize;
}

void FontUnit::setBold(bool bold)
{
    fontBold = bold;
}

bool FontUnit::isBold() const
{
    return fontBold;
}

void FontUnit::setItalic(bool italic)
{
    fontItalic = italic;
}

bool FontUnit::isItalic() const
{
    return fontItalic;
}

void FontUnit::setUnderline(bool underline)
{
    fontUnderline = underline;
}

bool FontUnit::isUnderline() const
{
    return fontUnderline;
}

QFont FontUnit::toFont() const
{
    QFont font(fontFamily, fontPointSize);
    font.setBold(fontBold);
    font.setItalic(fontItalic);
    font.setUnderline(fontUnderline);
    return font;
}

void FontUnit::fromFont(const QFont &font)
{
    fontFamily = font.family();
    fontPointSize = font.pointSize();
    fontBold = font.bold();
    fontItalic = font.italic();
    fontUnderline = font.underline();
}

